package com.longge;

public class PseudoPalindromicPaths {


    int ans = 0;

    public int pseudoPalindromicPaths(TreeNode root) {
        int[] count = new int[10];
        dfs(root, count);
        return ans;
    }


    private boolean checkPalindromic(int[] count) {
        int odd = 0;
        for (int i : count) {
            if (i % 2 == 1) odd++;
        }
        return odd <= 1;

    }

    private void dfs(TreeNode root, int[] count) {
        if (root == null) {
            return;
        }
        count[root.val]++;
        if (root.left == null && root.right == null) {
           if (checkPalindromic(count)) ans++;
        }
        dfs(root.left, count);
        dfs(root.right, count);
        count[root.val]--;
    }

}
